import org.junit.Test;

/**
 * Created by luoxf on 2018/9/8.
 */
public class Ip {

    @Test
    public void ipToLong() {
        String ip = "192.168.1.129";
        String[] ips = ip.split("\\.");
        long ipNum = 0;
        for (int i = 0; i < ips.length; i++) {
            ipNum += Long.parseLong(ips[i]) << 8 * (3 - i);
        }
        System.out.println(ipNum);
    }

    @Test
    public void longTpIp() {
        System.out.println(3232235905L >> 24);
        System.out.println(3232235905L&0xffffff >> 16);
        System.out.println(3232235905L&0x00ffff >> 8);
        System.out.println(3232235905L&0x00ff);
    }
}
